package com.lzq.PrototypePattern;

public class PrototypePattern {
    //抽象原型类
    public interface Prototype{
        /**
         * 克隆自身的方法
         * @return 一个从自身克隆出来的对象
         */
        public Object clone();
    }
    //具体原型类1
    public static class ConcretePrototype1 implements Prototype {
        ConcretePrototype1(){
            System.out.println("具体原型类1创建");
        }
        public Prototype clone(){
            //最简单的克隆，新建一个自身对象，由于没有属性就不再复制值了
            Prototype prototype = new ConcretePrototype1();
            return prototype;
        }
    }
    public static class ConcretePrototype2 implements Prototype{
        ConcretePrototype2(){
            System.out.println("具体原型类2创建");
        }
        public Prototype clone() {
            Prototype prototype = new ConcretePrototype2();
            return prototype;
        }
    }
    public static void main(String[] args){
        ConcretePrototype1 concretePrototype1 = new ConcretePrototype1();
        Prototype copyConcretePrototype1 = concretePrototype1.clone();
        ConcretePrototype2 concretePrototype2 = new ConcretePrototype2();
        Prototype copyConcretePrototype2 = concretePrototype2.clone();
    }
}
